//
// Created by cheng on 2021/02/02.
//

#ifndef ARITHMETICCHALLENGE_MYUTIL_H
#define ARITHMETICCHALLENGE_MYUTIL_H

#include <iostream>
#include <vector>
#include <string>

class MyUtil {
public:
    template <class T>
    static void PrintArray(T* array, int len) {
        std::cout << "array: {";
        for (int i = 0; i < len; ++i) {
            std::cout << array[i] << " ";
        }
        std::cout << "}" << std::endl;
    }

    template<class T>
    static void PrintVector(std::vector<T>& v) {
        std::cout << "vector: {";
        for (auto item : v) {
            std::cout << item << " ";
        }
        std::cout << "}" << std::endl;
    }

    template<class T>
    static void PrintVector(std::vector<T>& v, const std::string& vecName) {
        std::cout << vecName << ": {";
        for (auto item : v) {
            std::cout << item << " ";
        }
        std::cout << "}" << std::endl;
    }

    /**
     * 返回数组s中的最小值
     * @param s s[l..r]
     * @return min
     */
    template <class type>
    type Min(const type s[], int l, int r) {
        type s_min = s[l];
        for (int i = l + 1; i <= r; i++) {
            if (s_min > s[i]) {
                s_min = s[i];
            }
        }
        return s_min;
    }

    /**
     * 返回数组s中的最大值
     * @param s s[l..r]
     * @return max
     */
    template <class type>
    type Max(const type s[], int l, int r) {
        type s_max = s[l];
        for (int i = l + 1; i <= r; i++) {
            if (s_max < s[i]) {
                s_max = s[i];
            }
        }
        return s_max;
    }

    /**
     * 产生一个(min,max)之间的随机数
     */
    static int RandomInt(int min, int max);

    /**
     * 产生一个(min,max)之间的随机数
     */
    static float RandomFloat(float min, float max);

    /**
     * 生成一个长度为len，数值在（min,max)之间的vector
     */
    static std::vector<int> GetRandomIntVector(int len, int min, int max);

    static void GetRandomIntArray(int* arr, int len, int min, int max);

    static int Partition(std::vector<int> &arr, int left, int right);
};



#endif //ARITHMETICCHALLENGE_MYUTIL_H
